package com.wuge.gulimall.ware.controller;

import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Map;


import com.wuge.gulimall.ware.vo.PurchaseDoneVo;
import com.wuge.gulimall.ware.vo.PurchaseMergeVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.wuge.gulimall.ware.entity.PurchaseEntity;
import com.wuge.gulimall.ware.service.PurchaseService;
import com.wuge.common.utils.PageUtils;
import com.wuge.common.utils.R;



/**
 * 采购信息
 *
 * @author wuge
 * @email 1712378864@qq.com
 * @date 2021-07-19 12:31:59
 */
@RestController
@RequestMapping("ware/purchase")
public class PurchaseController {
    @Autowired
    private PurchaseService purchaseService;
//    /ware/purchase/received     [1,2,3,4]//采购单id
@PostMapping("/received")
// @RequiresPermissions("ware:purchase:save")
public R received(@RequestBody List<Long> ids){
    purchaseService.received(ids);

    return R.ok();
}
///ware/purchase/done
@PostMapping("/done")
// @RequiresPermissions("ware:purchase:save")
public R done(@RequestBody PurchaseDoneVo purchaseDoneVo){
    purchaseService.done(purchaseDoneVo);
    return R.ok();
}
    /**
     * 列表
     */
    @RequestMapping("/list")
    //@RequiresPermissions("ware:purchase:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = purchaseService.queryPage(params);

        return R.ok().put("page", page);
    }

@RequestMapping("/unreceive/list")
//@RequiresPermissions("ware:purchase:list")
public R getUnrceivelist(@RequestParam Map<String, Object> params){
    PageUtils page = purchaseService.queryPageUnrceive(params);

    return R.ok().put("page", page);
}
    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
  //  @RequiresPermissions("ware:purchase:info")
    public R info(@PathVariable("id") Long id){
		PurchaseEntity purchase = purchaseService.getById(id);

        return R.ok().put("purchase", purchase);
    }
///ware/purchase/merge
@PostMapping("/merge")
// @RequiresPermissions("ware:purchase:save")
public R merge(@RequestBody PurchaseMergeVo purchase){
    purchaseService.merge(purchase);

    return R.ok();
}
    /**
     * 保存
     */
    @RequestMapping("/save")
   // @RequiresPermissions("ware:purchase:save")
    public R save(@RequestBody PurchaseEntity purchase){
        purchase.setCreateTime(new Date());
		purchaseService.save(purchase);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
   // @RequiresPermissions("ware:purchase:update")
    public R update(@RequestBody PurchaseEntity purchase){
		purchaseService.updateById(purchase);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
   // @RequiresPermissions("ware:purchase:delete")
    public R delete(@RequestBody Long[] ids){
		purchaseService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
